module.exports = {
  preset: 'ts-jest',
  testEnvironment: 'node',
  roots: ['<rootDir>/src', '<rootDir>/tests'],
  testMatch: ['**/__tests__/**/*.ts', '**/?(*.)+(spec|test).ts'],
  transform: {
    '^.+\\.ts$': ['ts-jest', {
      tsconfig: {
        baseUrl: './src',
        paths: {
          '@/*': ['./*']
        }
      }
    }],
  },
  collectCoverageFrom: [
    'src/**/*.ts',
    '!src/**/*.d.ts',
    '!src/index.ts',
    '!src/**/__tests__/**',
    '!src/**/*.test.ts',
    '!src/**/*.spec.ts',
  ],
  coverageDirectory: 'coverage',
  coverageReporters: ['text', 'lcov', 'html'],
  coverageThreshold: {
    global: {
      branches: 70,  // 降低到更现实的水平
      functions: 70,
      lines: 70,
      statements: 70,
    },
  },
  moduleNameMapper: {
    '^@/(.*)$': '<rootDir>/src/$1',
  },
  setupFilesAfterEnv: ['<rootDir>/tests/setup.ts'],
  testTimeout: 30000, // 减少到 30 秒
  moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],

  // 性能优化配置
  maxWorkers: process.env.CI ? 2 : '50%', // CI环境使用2个worker，本地使用50%CPU
  maxConcurrency: 5, // 限制并发测试数量

  // 缓存配置
  cache: true,
  cacheDirectory: '<rootDir>/.jest-cache',

  // 静默配置
  silent: process.env.CI === 'true',
  verbose: process.env.VERBOSE_TESTS === 'true',
};
